<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="车间" prop="factoryCode">
        <el-select v-model="queryParams.factoryCode" placeholder="请选择车间">
          <el-option
            v-for="item in dict.type.bus_plant"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="熔炼炉名称" prop="smelterName">
        <el-input
          v-model="queryParams.smelterName"
          placeholder="请输入熔炼炉名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="牌号" prop="smelterNum">
        <el-input
          v-model="queryParams.smelterNum"
          placeholder="请输入牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['bus:detectionrlstandard:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['bus:detectionrlstandard:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['bus:detectionrlstandard:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['bus:detectionrlstandard:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="detectionrlstandardList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="业务主键ID" align="center" prop="id" />
      <el-table-column label="车间代号" align="center" prop="factoryCode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bus_plant" :value="scope.row.factoryCode"/>
        </template>
      </el-table-column>
      <el-table-column label="熔炼炉名称" align="center" prop="smelterName" />
      <el-table-column label="牌号" align="center" prop="smelterNum" />
      <el-table-column label="碳最小值" align="center" prop="cMin" />
      <el-table-column label="碳最大值" align="center" prop="cMax" />
      <el-table-column label="硅最小值" align="center" prop="siMin" />
      <el-table-column label="硫最大硅" align="center" prop="siMax" />
      <el-table-column label="锰最小值" align="center" prop="mnMin" />
      <el-table-column label="锰最大值" align="center" prop="mnMax" />
      <el-table-column label="磷最小值" align="center" prop="pMin" />
      <el-table-column label="磷最大值" align="center" prop="pMax" />
      <el-table-column label="硫最小值" align="center" prop="sMin" />
      <el-table-column label="硫最大值" align="center" prop="sMax" />
      <el-table-column label="钛最小值" align="center" prop="tiMin" />
      <el-table-column label="钛最大值" align="center" prop="tiMax" />
      <el-table-column label="铬最小值" align="center" prop="crMin" />
      <el-table-column label="铬最大值" align="center" prop="crMax" />
      <el-table-column label="铬最大值" align="center" prop="crMax" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['bus:detectionrlstandard:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['bus:detectionrlstandard:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改熔炼炉铁水标准对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="车间" prop="factoryCode">
              <el-select v-model="form.factoryCode" placeholder="请选择车间">
                <el-option
                  v-for="item in dict.type.bus_plant"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
            <el-col :span="12">
              <el-form-item label="牌号" prop="smelterNum">
                <el-input v-model="form.smelterNum" placeholder="请输入牌号" />
              </el-form-item>
            </el-col>
        </el-row>

        <el-form-item label="熔炼炉名称" prop="smelterName">
          <el-input v-model="form.smelterName" placeholder="请输入熔炼炉名称" />
        </el-form-item>

        <el-row>
          <el-col :span="8">
            <el-form-item label="碳最小值" prop="cMin">
              <el-input-number v-model="form.cMin" placeholder="请输入碳最小值" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="碳最大值" prop="cMax">
              <el-input-number v-model="form.cMax" placeholder="请输入碳最大值" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="硅最小值" prop="siMin">
              <el-input-number v-model="form.siMin" placeholder="请输入硅最小值" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="8">
            <el-form-item label="硫最大硅" prop="siMax">
              <el-input-number v-model="form.siMax" placeholder="请输入硫最大硅" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="锰最小值" prop="mnMin">
              <el-input-number v-model="form.mnMin" placeholder="请输入锰最小值" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="锰最大值" prop="mnMax">
              <el-input-number v-model="form.mnMax" placeholder="请输入锰最大值" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>

          <el-col :span="8">
            <el-form-item label="磷最小值" prop="pMin">
              <el-input-number v-model="form.pMin" placeholder="请输入磷最小值" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="磷最大值" prop="pMax">
              <el-input-number v-model="form.pMax" placeholder="请输入磷最大值" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="硫最小值" prop="sMin">
              <el-input-number v-model="form.sMin" placeholder="请输入硫最小值" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="硫最大值" prop="sMax">
              <el-input-number v-model="form.sMax" placeholder="请输入硫最大值" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="钛最小值" prop="tiMin">
              <el-input-number v-model="form.tiMin" placeholder="请输入钛最小值" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="钛最大值" prop="tiMax">
              <el-input-number v-model="form.tiMax" placeholder="请输入钛最大值" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="铬最小值" prop="crMin">
              <el-input-number v-model="form.crMin" placeholder="请输入铬最小值" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="铬最大值" prop="crMax">
              <el-input-number v-model="form.crMax" placeholder="请输入铬最大值" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDetectionrlstandard, getDetectionrlstandard, delDetectionrlstandard, addDetectionrlstandard, updateDetectionrlstandard } from "@/api/bus/detectionrlstandard";

export default {
  name: "Detectionrlstandard",
  dicts:['bus_plant'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 熔炼炉铁水标准表格数据
      detectionrlstandardList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        factoryCode: null,
        smelterName: null,
        smelterNum: null,
        cMin: null,
        cMax: null,
        siMin: null,
        siMax: null,
        mnMin: null,
        mnMax: null,
        pMin: null,
        pMax: null,
        sMin: null,
        sMax: null,
        tiMin: null,
        tiMax: null,
        crMin: null,
        crMax: null,
        deleted: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        factoryCode: [
          { required: true, message: '请选择车间', trigger: 'blur' }
        ],
        smelterName: [
          { required: true, message: '必填项', trigger: 'blur' },
        ],
        smelterNum: [
          { required: true, message: '必填项', trigger: 'blur' },
        ],
        cMin: [
          { required: true, message: '必填项', trigger: 'blur' },
        ],
        cMax: [
          { required: true, message: '必填项', trigger: 'blur' },
        ],
        siMin: [
          { required: true, message: '必填项', trigger: 'blur' },
        ],
        siMax: [
          { required: true, message: '必填项', trigger: 'blur' },
        ],
        mnMin: [
          { required: true, message: '必填项', trigger: 'blur' },
        ],
        mnMax: [
          { required: true, message: '必填项', trigger: 'blur' },
        ],
        sMin: [
          { required: true, message: '必填项', trigger: 'blur' },
        ],
        sMax: [
          { required: true, message: '必填项', trigger: 'blur' },
        ],
        pMin: [
          { required: true, message: '必填项', trigger: 'blur' },
        ],
        pMax: [
          { required: true, message: '必填项', trigger: 'blur' },
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询熔炼炉铁水标准列表 */
    getList() {
      this.loading = true;
      listDetectionrlstandard(this.queryParams).then(response => {
        this.detectionrlstandardList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryCode: null,
        smelterName: null,
        smelterNum: null,
        cMin: null,
        cMax: null,
        siMin: null,
        siMax: null,
        mnMin: null,
        mnMax: null,
        pMin: null,
        pMax: null,
        sMin: null,
        sMax: null,
        tiMin: null,
        tiMax: null,
        crMin: null,
        crMax: null,
        createTime: null,
        createBy: null,
        updateBy: null,
        updateTime: null,
        deleted: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加熔炼炉铁水标准";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDetectionrlstandard(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改熔炼炉铁水标准";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDetectionrlstandard(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDetectionrlstandard(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除熔炼炉铁水标准编号为"' + ids + '"的数据项？').then(function() {
        return delDetectionrlstandard(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('bus/detectionrlstandard/export', {
        ...this.queryParams
      }, `detectionrlstandard_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
